package com.ruoyi.project.poem.goodsposter.service.impl;

import com.ruoyi.common.utils.CacheUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.poem.goodsposter.domain.GoodsPoster;
import com.ruoyi.project.poem.goodsposter.mapper.GoodsPosterMapper;
import com.ruoyi.project.poem.goodsposter.service.IGoodsPosterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 今日好物Service业务层处理
 *
 * @author shixiangwen
 * @date 2021-06-24
 */
@Service
@DataSource(DataSourceType.POEM)
public class GoodsPosterServiceImpl implements IGoodsPosterService {

    @Autowired
    private GoodsPosterMapper goodsPosterMapper;

    /**
     * 查询今日好物
     *
     * @param id 今日好物ID
     * @return 今日好物
     */
    @Override
    public GoodsPoster selectGoodsPosterById(Long id) {
        return goodsPosterMapper.selectGoodsPosterById(id);
    }

    /**
     * 查询今日好物列表
     *
     * @param goodsPoster 今日好物
     * @return 今日好物
     */
    @Override
    public List<GoodsPoster> selectGoodsPosterList(GoodsPoster goodsPoster) {
        return goodsPosterMapper.selectGoodsPosterList(goodsPoster);
    }

    /**
     * 新增今日好物
     *
     * @param goodsPoster 今日好物
     * @return 结果
     */
    @Override
    public int insertGoodsPoster(GoodsPoster goodsPoster) {
        goodsPoster.setCreateTime(DateUtils.getNowDate());
        goodsPoster.setCreateUser(ShiroUtils.getLoginName());
        goodsPoster.setStatus(0);
        goodsPoster.setTargetType(1);
        return goodsPosterMapper.insertGoodsPoster(goodsPoster);
    }

    /**
     * 修改今日好物
     *
     * @param goodsPoster 今日好物
     * @return 结果
     */
    @Override
    public int updateGoodsPoster(GoodsPoster goodsPoster) {
        goodsPoster.setUpdateTime(DateUtils.getNowDate());
        CacheUtil.delete("default", "goods:poster:" + goodsPoster.getApp());
        return goodsPosterMapper.updateGoodsPoster(goodsPoster);
    }


    /**
     * 删除今日好物对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteGoodsPosterByIds(String ids) {
        return goodsPosterMapper.deleteGoodsPosterByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除今日好物信息
     *
     * @param id 今日好物ID
     * @return 结果
     */
    @Override
    public int deleteGoodsPosterById(Long id) {
        return goodsPosterMapper.deleteGoodsPosterById(id);
    }
}
